import request from '../utils/request'

/**
 *
 * @returns 根据选中的购物车商品生成订单预览
 */
export const previewOrder = () => {
  return request('/api/orders/preview', 'get')
}

/**
 *
 * @param {*} addressId - 地址id
 * @returns 生成的订单信息
 */
export const commitOrder = (addressId) => {
  return request('/api/orders', 'post', { address_id: addressId })
}

/**
 *
 * @param {String} order - 订单id
 * @param {String} type - 订单支付类型
 * @returns 获取支付二维码
 */
export const getPayCode = (order, type) => {
  return request(`/api/orders/${order}/pay`, 'get', { type })
}

/**
 *
 * @param {String} order - 订单id
 * @returns 获取支付状态信息
 */
export const getPayStatus = (order) => {
  return request(`/api/orders/${order}/status`, 'get')
}
